package com.xmlt.core.template.expression;

import com.xmlt.core.template.instance.AbstractInstance;
import com.xmlt.core.template.instance.Value;

import ognl.Ognl;
import ognl.OgnlException;

public class Expression {
	private Object expression;
	Expression(Object expr) {
		expression = expr;
	}
	
	public Object evaluate(AbstractInstance instance) throws OgnlException {
		return evaluate(instance, true);
	}
	
	public Object evaluate(AbstractInstance instance, boolean resolveValue) throws OgnlException {
		Object obj = Ognl.getValue(expression, instance);
		if (resolveValue && obj instanceof Value)
			obj = ((Value) obj).getValue();
		return obj;
	}
}
